<?php
add_action('widgets_init', 'register_top_movie');

function register_top_movie() {
    register_widget('top_movie');
}

class top_movie extends WP_Widget // widget class 
{

    function top_movie() { // widget setting | class name must be same function name
        $widget_ops = array('classname' => 'top-movie-w', 'description' =>
            'Display top lastest coupons - Home page or Store detail page');
        $control_ops = array(
            'width' => 250,
            'height' => 350,
            'id_base' => 'top_movie');
        $this->WP_Widget('top_movie', 'Top movies', $widget_ops, $control_ops);
    }

    function widget($args, $instance) { // display widget
        extract($args);
        $title = apply_filters('widget_title', $instance['title']);
        $show_items = $instance['show_items'];
        echo 'Title: '.$title.'<br/>';
        echo 'Number of items to show: '.$show_items;
    }

    function update($new_instance, $old_instance) { // update widget
        $instance = $old_instance;
        $instance['title'] = $new_instance['title'];
        $instance['show_items'] = $new_instance['show_items'];
        return $instance;
    }

    function form($instance) { // form for the widget options
        ?>
        <div style="color: #333;">
            <p>        
                <label for="<?php echo $this->get_field_id('title'); ?>"><?php echo 'Title'; ?></label>
                <input type="text" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $instance['title']; ?>" style="width:100%;" />
            </p>
            <p>
                <label for="<?php echo $this->get_field_id('show_items'); ?>"><?php echo 'Number of item to show'; ?></label>
                <input type="text" id="<?php echo $this->get_field_id('show_items'); ?>" name="<?php echo $this->get_field_name('show_items'); ?>" value="<?php echo $instance['show_items']; ?>" style="width:60%;" placeholder="ex: coupons, etc.." />
            </p>	     
        </div>
<?php
    }

}
?>
